package com.myhkvideo.yulongbpcdemo.task;

import com.myhkvideo.yulongbpcdemo.entity.TokenHolder;
import com.myhkvideo.yulongbpcdemo.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class TokenUpdateTask {

    @Autowired
    private LoginService loginService;

    @Scheduled(fixedRate = 1800000) // 每半个小时（1800000 毫秒）执行一次
    //@Scheduled(fixedRate = 10000) // 每半个小时（1800000 毫秒）执行一次
    public void updateToken() {
        String newToken = loginService.getNewToken();
        System.out.println(newToken);
        if (newToken != null) {
            TokenHolder.setToken(newToken);
        }
    }
}